home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11322 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!gmandel
  3. From: gmandel@netcom.com (Glenn Mandelkern)
  4. Subject: Re: mixing static and const qualifiers for class members
  5. Message-ID: <gmandelDo88xo.228@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <4i6mu3$pmg@halon.vggas.com> <4i6uga$67v@cloner3.netcom.com>
  8. Date: Wed, 13 Mar 1996 22:25:00 GMT
  9. Sender: gmandel@netcom20.netcom.com
  10.  
  11. In article <4i6uga$67v@cloner3.netcom.com>,
  12. Michael Judge  <mjudge@ix.netcom.com> wrote:
  13. >In <4i6mu3$pmg@halon.vggas.com> JYoungman@vggas.com (James Youngman)
  14. >writes: 
  15. >>
  16. >>How do I declare and initialise a one-per-class constant?  I want to
  17. >do 
  18. >>something like this:
  19. >>
  20. >>class Foo
  21. >>{
  22. >>    static const int nPositions = 6;
  23. >>    int nData[nPositions];
  24. >>}
  25. >>
  26. >>...how is this done?
  27. >>James.
  28. >>
  29. >
  30. >class Foo
  31. >{
  32. >    enum {nPositions=6};
  33. >    int nData[nPositions];
  34. >};
  35. >
  36.  
  37. FYI, the recommended solution of using the unnamed enum is found on
  38. page 291 of "Thinking in C++" by Bruce Eckel.
  39.  
  40. Also, page 351 of the same book shows the static const int
  41. example exactly as the original poster had it.  According to
  42. the footnote on that page, some compilers may not support
  43. this feature of having a static const within a class.
  44.  
  45. -- 
  46.  ---------------------------------------------------------------------------
  47. Glenn Mandelkern                     "Hee, hee, hee, hee!" -- Questor the Elf
  48. gmandel@netcom.com                   "When passion runs deep,
  49. San Jose, CA                         you're playing for keeps" -- Keith Emerson
  50. Games, GUI's and Entertainment    What does Motif sound like in the key of C++?
  51.  
  52.